home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Magazine 28 Bonus / CDRomMagazine-SoftKey-ArtPassion-FrenchVersion-Win31Mac.bin / data / cnfeepl.dir / 00016_Script_MAIN HANDLERS < prev    next >
Text File  |  1996-06-18  |  7KB  |  233 lines

  1. -- What is this?
  2. -- The FeelingsGame. Drag a shape button to one of the frames and express your own
  3. -- feeling. A shape will 'snap back' to it's button when not released in a frame and
  4. -- you canonly drag 5 of every shapes. After that, the button will grey out and is not active.
  5.  
  6. -- How does it work?
  7. -- On top of each shape button at te bottom of the screen are 5 empty sprites.Each sprite contains
  8. -- a call to handler processClick when clicked. Then the corresponding castmember (a shape)  is 
  9. -- substituted for the castmember of the empty sprite.While dragged, it follows the mouse and when
  10. -- released it stays in place (if it's within an invisible castmember ofverlaying the painting
  11. -- frame or snaps back if it's not. A counter keeps track of te amount of shapes used for each 
  12. -- button. If this is 5 (max) then the castmember of the last empty sprite overlaying the button 
  13. -- is switched for a grayed out version of the button.
  14.  
  15.  
  16. on initGame
  17.   
  18.   global paintingSpritesList
  19.   global buttonShapesSpritesSizeWList,buttonShapesSpritesSizeHList
  20.   global cCrook,cTriangle,caLine,cSquare,cCircle,cinvTriangle
  21.   global firstShapeSprite,lastShapeSprite,ExampleButtonsSprite
  22.   global placedSprites
  23.   
  24.   -- set the puppets of the shapes buttons
  25.   set firstShapeSprite = 10
  26.   set lastShapeSprite = 39
  27.   setPuppetsFromTo 10,39,1
  28.   
  29.   -- set the counters of the shapes to 0
  30.   set cCrook = 0
  31.   set cTriangle = 0
  32.   set caLine = 0
  33.   set cSquare = 0
  34.   set cCircle = 0
  35.   set cinvTriangle = 0
  36.   
  37.   -- these are the Horizontal coordinates of the sprites containing the shapes
  38.   set buttonShapesSpritesSizeWList = [Crook:41,aTriangle:46,aLine:5,Square:40,Circle:31,InvTriangle:28]
  39.   
  40.   -- these are the Vertical coordinates of the sprites containing the shapes
  41.   set buttonShapesSpritesSizeHList= [Crook:72,aTriangle:33,aLine:59,Square:45,¼
  42. Circle:31,InvTriangle:24]
  43.   
  44.   -- these are the nrs of the invisible sprites overlaying the painting frames
  45.   set paintingSpritesList = [6,7,8,9]
  46.   
  47.   -- initialize the list that contains the spritenrs of shapes that are dragged
  48.   set placedSprites = []
  49.   
  50. end initGame
  51.  
  52.  
  53. on processClick aSprite,aShape
  54.   global buttonShapesSpritesSizeWList,buttonShapesSpritesSizeHList
  55.   
  56.   -- remember original position of buttonsprite if you have to reset it (resetShape)
  57.   set oldShapeLocH = the locH of sprite aSprite
  58.   set oldShapeLocV = the locV of sprite aSprite
  59.   set oldLoc = [oldShapeLocH,oldShapeLocV]
  60.   
  61.   -- remember the castNr of the empty buttonSprite if you have to reset it (resetShape)
  62.   set oldCast = the castNum of sprite aSprite
  63.   
  64.   -- remember the size of the empty buttonSprite if you have to reset it (resetShape)
  65.   set oldSpriteHeight = the height of sprite aSprite
  66.   set oldSpriteWidth = the width of sprite aSprite
  67.   set oldSpriteSize = [oldSpriteHeight,oldSpriteWidth]
  68.   
  69.   -- change the empty buttonSprite size to the shape's size
  70.   set the width of sprite aSprite to (getAProp(buttonShapesSpritesSizeWList,aShape))
  71.   set the height of sprite aSprite to (getAProp(buttonShapesSpritesSizeHList,aShape))
  72.   
  73.   updateStage
  74.   
  75.   -- change empty buttonSprite to the shape
  76.   set the castNum of sprite aSprite to the number of cast string(aShape)
  77.   
  78.   -- drag shape
  79.   repeat while the stillDown
  80.     set the locH of sprite aSprite to the mouseH
  81.     set the locV of sprite aSprite to the mouseV
  82.     updateStage
  83.   end repeat
  84.   
  85.   -- shape is dropped - check
  86.   if NOT intoFrame(aSprite) then resetShape aSprite,oldCast,oldLoc,oldSpriteSize
  87.   else
  88.     if NOT firstTimeShapeDragged(aSprite) then 
  89.       addCounter aShape,aSprite
  90.       addShapeToPlacedShapesList(aSprite) -- add the sprite that's already dragged to a list
  91.     end if
  92.   end if
  93.   
  94. end processClick
  95.  
  96.  
  97. -- when shape is dropped, & it is IN a picture frame, leave it there
  98. -- when shape is dropped, & it is NOT IN a picture frame, snap back to button
  99. on intoFrame aSprite
  100.   global paintingSpritesList
  101.   
  102.   set snappedIntoPlace = FALSE
  103.   set i = 1
  104.   
  105.   repeat while (NOT snappedIntoPlace) AND (i <= 4)
  106.     set currPaintingFrame = getAt(paintingSpritesList,i)
  107.     if sprite aSprite within currPaintingFrame then set snappedIntoPlace = TRUE
  108.     set i = i + 1
  109.   end repeat
  110.   
  111.   return snappedIntoPlace
  112.   
  113. end intoFrame
  114.  
  115.  
  116. on resetShape aSprite,oldCastNr,oldPos,oldSize
  117.   -- reset cast
  118.   set the castNum of sprite aSprite to oldCastNr
  119.   
  120.   -- reset location
  121.   set the locH of sprite aSprite to getAt(oldPos,1)
  122.   set the locV of sprite aSprite to getAt(oldPos,2)
  123.   
  124.   -- reset size
  125.   set the height of sprite aSprite = getAt(oldSize,1)
  126.   set the width of sprite aSprite = getAt(oldSize,2)
  127.   
  128. end resetShape
  129.  
  130.  
  131. -- keep track how many shapes are used.
  132. on addCounter aShape,aSprite
  133.   global cCrook,cTriangle,caLine,cSquare,cCircle,cinvTriangle
  134.   
  135.   if aShape = "Crook" then
  136.     set cCrook = cCrook + 1
  137.     checkCounter cCrook,"Crook",aSprite
  138.   end if
  139.   
  140.   if aShape = "aTriangle" then
  141.     set cTriangle = cTriangle + 1
  142.     checkCounter cTriangle,"aTriangle",aSprite
  143.   end if
  144.   
  145.   if aShape = "aLine" then
  146.     set caLine = caLine + 1
  147.     checkCounter caLine,"aLine",aSprite
  148.   end if
  149.   
  150.   if aShape = "Square" then
  151.     set cSquare = cSquare + 1
  152.     checkCounter cSquare,"Square",aSprite
  153.   end if
  154.   
  155.   if aShape = "Circle" then
  156.     set cCircle = cCircle + 1
  157.     checkCounter cCircle,"Circle",aSprite
  158.   end if
  159.   
  160.   if aShape = "invTriangle" then
  161.     set cinvTriangle = cinvTriangle + 1
  162.     checkCounter cinvTriangle,"invTriangle",aSprite
  163.   end if
  164.   
  165. end addCounter
  166.  
  167.  
  168. -- Change the shapebutton to Inactive (grey) when the last shape is used
  169. on checkCounter aCounter,aShape,aSprite
  170.   
  171.   set lastSprite = aSprite - 1
  172.   
  173.   if aCounter = 4 then 
  174.     disableButton lastSprite
  175.   end if
  176.   updateStage
  177.   
  178. end checkCounter
  179.  
  180. -- handler shapePlacedInFrame adds a sprite to a list
  181.  
  182. on addShapeToPlacedShapesList aSprite
  183.   global placedSprites
  184.   add(placedSprites, aSprite)
  185. end
  186.  
  187.  
  188. on firstTimeShapeDragged aSprite
  189.   global placedSprites
  190.   return inList(placedSprites,aSprite) 
  191. end
  192.  
  193.  
  194. -- --------------------------------------------------------
  195. -- Handler pressButton changes the apparance of the button
  196. -- to it's pressed equivalent as long as user presses the mouse
  197. -- and the cursor is over the button
  198.  
  199. on pressButton
  200.   global buttonPressed
  201.   
  202.   repeat while the mouseDown
  203.     if NOT rollOver(the clickOn) then
  204.       changeButtonCast the clickOn, "out"
  205.       set buttonPressed = FALSE
  206.     else
  207.       changeButtonCast the clickOn, "in"
  208.       set buttonPressed = TRUE
  209.     end if
  210.     updateStage
  211.   end repeat
  212.   
  213.   changeButtonCast the clickOn, "out" 
  214.   
  215. end
  216.  
  217. -- ---------------------------------------------------------------
  218. -- Handler inList returns TRUE if 'anItem' is in the list 'aList',
  219. -- FALSE if 'anItem' is not in the list 'aList'.
  220.  
  221. on inList aList,anItem
  222.   set result = FALSE
  223.   
  224.   repeat with i = 1 to count(aList)
  225.     if getAt(aList,i) = anItem then
  226.       set result = TRUE
  227.       exit repeat
  228.     end if
  229.   end repeat
  230.   
  231.   return result
  232.   
  233. end